package com.ambitor.ipro.actions;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;

import com.ambitor.ipro.util.Constants;

public class SettingPersistAction extends BaseAction {

	private static final long serialVersionUID = -2528418471608896211L;

	private Map<String, String> ipro;

	public SettingPersistAction() {
	}

	public Map<String, String> getIpro() {
		return ipro;
	}

	public void setIpro(Map<String, String> ipro) {
		this.ipro = ipro;
	}

	@Override
	@SuppressWarnings("unchecked")
	public String execute() throws UnsupportedEncodingException {
		if (ipro != null) {
			String encodedTitle = ipro.get("promote_title");
			if (encodedTitle != null)
				ipro.put("promote_title", URLDecoder.decode(encodedTitle,
						Constants.APPLICATION_ENCODING));
		}

		Object obj = pd.getSessionAttribute(Constants.PRO_SETTING);
		if (obj == null) {
			pd.setSessionAttribute(Constants.PRO_SETTING, new HashMap());
		} else {
			Map<String, String> oldProInSession = (Map<String, String>) obj;
			if (ipro != null)
				oldProInSession.putAll(ipro);
			pd.setSessionAttribute(Constants.PRO_SETTING, oldProInSession);

		}
		return SUCCESS;
	}
}
